﻿using System.Collections.ObjectModel;
using T4UtilityBelt.DataDesigns;
using T4UtilityBelt.UxDesigns.Interfaces;
using T4UtilityBelt.Writers;

namespace T4UtilityBelt.UxDesigns.Controls
{
    public class ControlCollection<T> : Collection<T>
        where T : Control
    {
        #region Render Methods

        public void RenderUiXml(CodeWriter writer)
        {
            foreach (T c in this)
            {
                c.RenderUiXml(writer);
            }
        }

        public string RenderUiXml(Platforms platform)
        {
            CodeWriter writer = new CodeWriter(platform);
            RenderUiXml(writer);
            return writer.ToString();
        }

        public void RenderViewModelCs(CodeWriter writer)
        {
            foreach (T c in this)
            {
                c.RenderViewModelCs(writer);
            }
        }

        public string RenderViewModelCs(Platforms platform)
        {
            CodeWriter writer = new CodeWriter(platform);
            RenderViewModelCs(writer);
            return writer.ToString();
        }

        #endregion
    }

    public class ControlCollection : ControlCollection<Control>
    {
        public void FixModel(Entity entity)
        {
            foreach (Control ctl in this)
            {
                ctl.FixModel(entity);
            }
        }

        public void Switch(Control oldControl, Control newControl)
        {
            if (oldControl != null)
            {
                Remove(oldControl);
            }
            if (newControl != null)
            {
                Add(newControl);
            }
        }
    }
}